//app.js
const http="https://member-api.bauschlombchina.com/";
const session = "DB900369048A2F0B9A92AAEB12D162C71E166A8C411F0BB2392E23F59D73924840775AB9D02E073037F986BBB1F56CC1BA389A3AE85EAE7745F8AD3D34D14EAD9503200E8AD3E43176FCD414FE944D4015A4F04E5B7A5F4962F68E87BAA0EF3B49B8BF4B2C141A507AECE61D5154D539677B48FB6C51ADDA876B232BD8DBEF65"
App({
  onLaunch: function () {
    
  },
  post(url,params){
    return new Promise((resolve,reject)=>{
      try {
        wx.request({
          url: http + url,
          header:{
            session:session
          },
          method:"POST",
          data:params,
          success:res=>{
            if(res.data.errcode == 0){
                resolve(res.data.result)
            }else{
              wx.showToast({
                title: res.data.errmsg,
                icon:'none'
              })
              reject(1)
            }
          }
        })
      } catch (error) {
          wx.showToast({
            title: error,
            icon:"none"
          })
          reject()
      }
       
    })
  },
  formatDate(date, fmt) {
    var currentDate = new Date(date);
    var o = {
      "M+": currentDate.getMonth() + 1, //月份
      "d+": currentDate.getDate(), //日
      "h+": currentDate.getHours(), //小时
      "m+": currentDate.getMinutes(), //分
      "s+": currentDate.getSeconds(), //秒
      "q+": Math.floor((currentDate.getMonth() + 3) / 3), //季度
      "S": currentDate.getMilliseconds() //毫秒
    };
    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (currentDate.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
      if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
  },
  globalData: {
    userInfo: null
  }
})